﻿using System;
using System.Text;

namespace Demo4.EventDemo
{
    public class Stock
    {
        private string symbol;
        private decimal price;
        public event EventHandler<PriceChangedEventArgs> PriceChanged;

        public decimal Price
        {
            get => price;
            set
            {
                if (price == value)
                {
                    return;
                }
                if (PriceChanged != null)
                {
                    OnPriceChanged(new PriceChangedEventArgs(price, value));
                }
                price = value;
            }
        }

        protected virtual void OnPriceChanged(PriceChangedEventArgs e)
        {
            PriceChanged?.Invoke(this, e);
        }
    }
}